
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 1
 * @Author : WangRuoyu 
 * @Date : 2023/5/16 16:05
 */

#include "iostream"

using namespace std;

int main() {
    int r, y, g, n;
    cin >> r >> y >> g >> n;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int k, t;
        cin >> k >> t;
        if (k == 0 || k == 1) {
            res += t;
        } else if (k == 2) {
            res += t + r;
        }
    }
    cout << res;
    return 0;
}